#!/bin/sh

#
# --- VARIABLES A MODIFIER
#
NOM_MODULE=ORB_PartyManager
JAVA_PATH=/usr/bin
JDK_PATH=/usr/lib/jvm/java-1.6.0-openjdk

#
# --- VARIABLES GLOBALES
#
JAVAC="$JAVA_PATH"/javac
IDLJ="$JDK_PATH"/bin/idlj
JAR_PATH=../lib
CLASSPATH=Shared/class/:Tier1/class/:Tier2/class/:"$JAR_PATH"/jsr311-api.jar:"$JAR_PATH"/jersey-gf-bundle.jar

#
# --- DIRECTIVES DE COMPILATION
#
case "$1" in
orb)
	echo "\nGeneration des classes ORB\n"
	rm *.java
	"$IDLJ" -fall -pkgPrefix "$NOM_MODULE" Tier2 ./"$NOM_MODULE".idl
	mv Tier2/"$NOM_MODULE"/* .
	rmdir Tier2/"$NOM_MODULE"
	rmdir Tier2

;;
class)
	echo "\nCompilation des classes\n"
	cd ../..

	if [ ! -d Shared/class ]; then mkdir Shared/class; fi
	if [ ! -d Tier2/class ]; then mkdir Tier2/class; fi
	if [ ! -d Tier1/class ]; then mkdir Tier1/class; fi

	"$JAVAC" -classpath "$CLASSPATH"  -d Shared/class Shared/*.java
	"$JAVAC" -classpath "$CLASSPATH"  -d Tier2/class Tier2/*/*.java
	"$JAVAC" -classpath "$CLASSPATH"  -d Tier2/class Tier2/*.java
	"$JAVAC" -classpath "$CLASSPATH"  -d Tier1/class Tier1/*.java
;;
serveur)
	echo "\nLance le serveur ORB\n"
	cd ../..
	java -classpath "$CLASSPATH" Tier2/ServeurIIOP -ORBInitialPort 2000 -ORBInitialHost 127.0.0.1
;;
client)
	echo "\nLance le client ORB\n"
	cd ../..
	java -classpath "$CLASSPATH" Tier1/UserIIOP -ORBInitialPort 2000 -ORBInitialHost 127.0.0.1
;;
*)
	echo "Usage: compile.sh {orb|class|serveur|client}"
esac
